// 封装删除管理员请求路由


//引入express模块
const express = require("express")

//创建一个路由
const route = express.Router()

// 引入token校验中间件
const isLoginMiddle = require("../middleware/isLoginMiddle")

//引入数据库集合对象
const adminModel = require("../db/model/adminModel")

//设置删除管理员的路由
route.delete("/deleteAdmin", isLoginMiddle, async (req, res) => {
    const {
        adminName
    } = req.query

    try {
        const deleteResult = await adminModel.deleteOne({
            adminName
        })
        // console.log(deleteResult);
        if (deleteResult.deletedCount > 0) {
            return res.send({
                code: 10000,
                msg: "删除管理员" + adminName + "成功",
                data: null
            })
        }

        res.send({
            code: 10001,
            msg: "删除管理员" + adminName + "失败",
            data: null
        })
    } catch (e) {
        console.log("删除管理员失败" + e.message);
        res.send({
            code: 10001,
            msg: "删除管理员异常" + e.message,
            data: null
        })
    }

})


//暴露路由
module.exports = route